/*
package org.jeecg.modules.api.wlhy.app.utils;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;

@Component
public class JTTUtils {

    @Autowired
    private TokenTimer tokenTimer=new TokenTimer();


    */
/**
     * 上传位置信息
     * @param bean
     * @param clazz
     * @return
     * @throws IOException
     *//*

    public  Response uploadLocation(UploadLocationInfoBean bean,Class<?> clazz) throws IOException {
        String ss = UUID.randomUUID().toString().replaceAll("-","");
        Request req = new Request(ss,"位置信息单","130058","0191130108MA09WMFW72","WLHY_WZCX1001",tokenTimer.getToken(),bean);
        System.out.println(JSONObject.toJSONString(req));
        String sb = HttpUtils.sendPost("http://112.33.20.80:20020/a/wlhyCO/uploadData", JSONObject.toJSONString(req));
        JSONObject json = JSONObject.parseObject(sb);
        Response res = JSONObject.parseObject(json.toString(),Response.class);
        if(clazz != null){
            res.setData(JSONObject.parseObject(json.getString("data"),clazz.getClass()));
        }
        res.setMessageReferenceNumber(ss);
        return res;
    }

    */
/**
     * 上传司机信息
     * @param bean
     * @param clazz
     * @return
     * @throws IOException
     *//*

    public  Response uploadDriver(UploadDriverBaseInfoBean bean, Class<?> clazz) throws IOException {
        String ss = UUID.randomUUID().toString().replaceAll("-","");
        Request req = new Request(ss,"驾驶员信息单","130058","1391130108MA09WMFW72","WLHY_JSY1001",tokenTimer.getToken(),bean);
        System.out.println(JSONObject.toJSONString(req));
        String sb = HttpUtils.sendPost("http://112.33.20.80:20020/a/wlhyCO/uploadData", JSONObject.toJSONString(req));
        JSONObject json = JSONObject.parseObject(sb.toString());
        Response res = JSONObject.parseObject(json.toString(),Response.class);
        if(clazz != null){
            res.setData(JSONObject.parseObject(json.getString("data"),clazz.getClass()));
        }
        res.setMessageReferenceNumber(ss);
        return res;
    }

    */
/**
     * 上传车辆信息
     * @param bean
     * @param clazz
     * @return
     * @throws IOException
     *//*

    public  Response uploadCar(UploadCarBaseInfoBean bean, Class<?> clazz) throws IOException {
        String ss = UUID.randomUUID().toString().replaceAll("-","");
        Request req = new Request(ss,"车辆信息单","130058","0191130108MA09WMFW72","WLHY_CL1001",tokenTimer.getToken(),bean);
        System.out.println(JSONObject.toJSONString(req));
        String sb = HttpUtils.sendPost("http://112.33.20.80:20020/a/wlhyCO/uploadData", JSONObject.toJSONString(req));
        JSONObject json = JSONObject.parseObject(sb.toString());
        Response res = JSONObject.parseObject(json.toString(),Response.class);
        if(clazz != null){
            res.setData(JSONObject.parseObject(json.getString("data"),clazz.getClass()));
        }
        res.setMessageReferenceNumber(ss);
        return res;
    }

    */
/**
     * 上传资金流水
     * @param bean
     * @param clazz
     * @return
     * @throws IOException
     *//*

    public  Response uploadZjls(UploadZJLSBean bean,Class<?> clazz) throws IOException {
        String ss = UUID.randomUUID().toString().replaceAll("-","");
        Request req = new Request(ss,"资金流水单","130058","0191130108MA09WMFW72","WLHY_ZJ1001",tokenTimer.getToken(),bean);
        System.out.println(JSONObject.toJSONString(req));
        String sb = HttpUtils.sendPost("http://112.33.20.80:20020/a/wlhyCO/uploadData", JSONObject.toJSONString(req));
        JSONObject json = JSONObject.parseObject(sb.toString());
        Response res = JSONObject.parseObject(json.toString(),Response.class);
        if(clazz != null){
            res.setData(JSONObject.parseObject(json.getString("data"),clazz.getClass()));
        }
        res.setMessageReferenceNumber(ss);
        return res;
    }

    */
/**
     * 上传运单
     * @param bean
     * @param clazz
     * @return
     * @throws IOException
     *//*

    public  Response uploadYd(UploadYDBean bean,Class<?> clazz) throws IOException {
        tokenTimer=new TokenTimer();
        String ss = UUID.randomUUID().toString().replaceAll("-","");
        Request req = new Request(ss,"电子运单","130058","0191130108MA09WMFW72","WLHY_YD1001",tokenTimer.getToken(),bean);
        System.out.println(JSONObject.toJSONString(req));
        String sb = HttpUtils.sendPost("http://112.33.20.80:20020/a/wlhyCO/uploadData", JSONObject.toJSONString(req));
        JSONObject json = JSONObject.parseObject(sb.toString());
        Response res = JSONObject.parseObject(json.toString(),Response.class);
        if(clazz != null){
            res.setData(JSONObject.parseObject(json.getString("data"),clazz.getClass()));
        }
        res.setMessageReferenceNumber(ss);
        return res;
    }


    //运单
    public static void main2(String[] args) throws IOException {

//        UploadYDBean bean = new UploadYDBean();
//        bean.setOriginalDocumentNumber("987654321");
//        bean.setShippingNoteNumber("123456789");
//        bean.setSerialNumber("1234");
//        bean.setVehicleAmount("1");
//        bean.setTransportTypeCode("1");
//        bean.setSendToProDateTime("20201228182233");
//        bean.setCarrier("河北八秒科技有限公司");
//        bean.setUnifiedSocialCreditIdentifier("91130108MA09WMFW72");
//        bean.setPermitNumber("130101015175");
//        bean.setConsignmentDateTime("20201228182455");
//        bean.setBusinessTypeCode("1002996");
//        bean.setDespatchActualDateTime("20201228182533");
//        bean.setGoodsReceiptDateTime("20201228182511");
//        ConsignorInfoBean consignorInfoBean = new ConsignorInfoBean();
//        consignorInfoBean.setConsignor("张三");
//        consignorInfoBean.setConsignorId("130182198606031523");
//        consignorInfoBean.setCountrySubdivisionCode("130109");
//        consignorInfoBean.setPlaceOfLoading("藁城区");
//        bean.setConsignorInfo(consignorInfoBean);
//        ConsigneeInfoBean consigneeInfo = new ConsigneeInfoBean();
//        consigneeInfo.setConsignee("李四");
//        consigneeInfo.setConsigneeID("130182198606031525");
//        consigneeInfo.setCountrySubdivisionCode("130110");
//        consigneeInfo.setGoodsReceiptPlace("鹿泉区");
//        bean.setConsigneeInfo(consigneeInfo);
//        bean.setTotalMonetaryAmount(new BigDecimal(100.251));
//        VehicleInfoBean vehicleInfoBean = new VehicleInfoBean();
//        vehicleInfoBean.setVehicleNumber("冀A196A0");
//        vehicleInfoBean.setVehiclePlateColorCode("2");
//        vehicleInfoBean.setDespatchActualDateTime("20201228183122");
//        vehicleInfoBean.setGoodsReceiptDateTime("20201228183111");
//        vehicleInfoBean.setPlaceOfLoading("高城区");
//        vehicleInfoBean.setLoadingCountrySubdivisionCode("004");
//        vehicleInfoBean.setGoodsReceiptPlace("鹿泉区");
//        vehicleInfoBean.setReceiptCountrySubdivisionCode("004");
//        DriverBean driverBean = new DriverBean();
//        driverBean.setDriverName("张建路");
//        driverBean.setDrivingLicense("13292419711011811");
//        vehicleInfoBean.setDriver(driverBean);
//        GoodsInfoBean goodsInfoBean = new GoodsInfoBean();
//        goodsInfoBean.setDescriptionOfGoods("海洛因");
//        goodsInfoBean.setCargoTypeClassificationCode("1700");
//        goodsInfoBean.setGoodsItemGrossWeight("100.021");
//        goodsInfoBean.setCube("12.022");
//        goodsInfoBean.setTotalNumberOfPackages("1");
//        vehicleInfoBean.setGoodsInfo(goodsInfoBean);
//        bean.setVehicleInfo(vehicleInfoBean);
//        ActualCarrierInfoBean actualCarrierInfoBean = new ActualCarrierInfoBean();
//        actualCarrierInfoBean.setActualCarrierName("河北八秒科技有限公司");
//        actualCarrierInfoBean.setActualCarrierBusinessLicense("130101015175");
//        actualCarrierInfoBean.setActualCarrierID("91130108MA09WMFW72");
//        bean.setActualCarrierInfo(actualCarrierInfoBean);
//        InsuranceInformationBean insuranceInformationBean = new InsuranceInformationBean();
//        insuranceInformationBean.setInsuranceCompanyCode("none");
//        insuranceInformationBean.setPolicyNumber("none");
//        bean.setInsuranceInformation(insuranceInformationBean);
//        Response response = new JTTUtils().uploadYd(bean, null);
//        System.out.println("============");

        Workbook wb =null;
        Sheet sheet = null;
        Row row = null;
        List<UploadYDBean> list = null;
        String cellData = null;
        String filePath = "E:\\八秒车辆信息记录2.xlsx";
        String columns[] = {"originalDocumentNumber","shippingNoteNumber","vehicleAmount","serialNumber","transportTypeCode","sendToProDateTime","carrier","unifiedSocialCreditIdentifier","permitNumber","consignmentDateTime","businessTypeCode","despatchActualDateTime","goodsReceiptDateTime"};
        wb = readExcel(filePath);
        if(wb != null){
            //用来存放表中数据
            list = new ArrayList<UploadYDBean>();
            //获取第一个sheet
            sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            //获取第一行
            row = sheet.getRow(0);
            //获取最大列数
            int colnum = row.getPhysicalNumberOfCells();
            for (int i = 1; i<rownum; i++) {
//                Map<String,String> map = new LinkedHashMap<String,String>();
                UploadYDBean uploadYDBean=new UploadYDBean();
                row = sheet.getRow(i);
                if(row !=null){
                    for (int j=0;j<colnum;j++){
                        row.getCell(j).setCellType(Cell.CELL_TYPE_STRING);
                        cellData = (String) getCellFormatValue(row.getCell(j));
//                        cellData= row.getCell(j).getRichStringCellValue().getString();
//                        if(columns[j].equals("vehicleNumber")){
//                            uploadCarBaseInfoBean.setVehicleNumber(cellData);
//                        }else  if(columns[j].equals("vehiclePlateColorCode")){
//                            uploadCarBaseInfoBean.setVehiclePlateColorCode(cellData);
//                        }else  if(columns[j].equals("vehicleType")){
//                            uploadCarBaseInfoBean.setVehicleType(cellData);
//                        }else  if(columns[j].equals("owner")){
//                            uploadCarBaseInfoBean.setOwner(cellData);
//                        }else  if(columns[j].equals("vin")){
//                            uploadCarBaseInfoBean.setVin(cellData);
//                        }else  if(columns[j].equals("useCharacter")){
//                            uploadCarBaseInfoBean.setUseCharacter(cellData);
//                        }else  if(columns[j].equals("issuingOrganizations")){
//                            uploadCarBaseInfoBean.setIssuingOrganizations(cellData);
//                        }else  if(columns[j].equals("registerDate")){
//                            uploadCarBaseInfoBean.setRegisterDate(cellData);
//                        }else  if(columns[j].equals("issueDate")){
//                            uploadCarBaseInfoBean.setIssueDate(cellData);
//                        }else  if(columns[j].equals("vehicleEnergyType")){
//                            uploadCarBaseInfoBean.setVehicleEnergyType(cellData);
//                        }else  if(columns[j].equals("vehicleTonnage")){
//                            uploadCarBaseInfoBean.setVehicleTonnage(new BigDecimal(cellData));
//                        }else  if(columns[j].equals("grossMass")){
//                            uploadCarBaseInfoBean.setGrossMass(new BigDecimal(cellData));
//                        }else  if(columns[j].equals("roadTransportCertificateNumber")){
//                            uploadCarBaseInfoBean.setRoadTransportCertificateNumber(cellData);
//                        }

                    }
                }else{
                    break;
                }
                list.add(uploadYDBean);
            }
        }
        if(list.size()>0){
            for(UploadYDBean uploadYDBean:list){
                Response response = new JTTUtils().uploadYd(uploadYDBean, null);
                System.out.println(JSONObject.toJSON(response));
                System.out.println("============");
            }
        }
    }
    //资金流水
    public static void main4(String[] args) throws IOException {
        UploadZJLSBean bean = new UploadZJLSBean();
        bean.setSendToProDateTime("20201228180422");
        bean.setVehicleNumber("冀A196A0");
        bean.setVehiclePlateColorCode("2");
        bean.setActualCarrierId("91130108MA09WMFW72");
        bean.setCarrier("河北八秒科技有限公司");
        bean.setDocumentNumber(UUID.randomUUID().toString().replaceAll("-",""));
        List<shippingNoteBean> shippings = new ArrayList<>();
        shippingNoteBean shipping = new shippingNoteBean();
        shipping.setSerialNumber("1234");
        shipping.setShippingNoteNumber("8888888888");
        shipping.setTotalMonetaryAmount(new BigDecimal(100.250));
        shippings.add(shipping);
        bean.setShippingNoteList(shippings);
        List<financialBean> financials = new ArrayList<>();
        financialBean financial = new financialBean();
        financial.setBankCode("PCBC");
        financial.setPaymentMeansCode("32");
        financial.setRecipient("河北八秒科技有限公司");
        financial.setDateTime("20201228181222");
        financial.setMonetaryAmount(new BigDecimal(100.250));
        financial.setSequenceCode("98512545226655");
        financial.setReceiptAccount("13050161513700000675");
        financials.add(financial);
        bean.setFinanciallist(financials);
        Response response = new JTTUtils().uploadZjls(bean, null);
        System.out.println("============");
    }
    public static void main3(String[] args) throws IOException {
        UploadLocationInfoBean location = new UploadLocationInfoBean();
        location.setCountrySubdivisionCode("130133");
        location.setLatitude("36.25554");
        location.setLongitude("36.2542");
        location.setLocationText("");
        location.setSendDateTime("20201228174425");
        location.setShippingNoteNumber(UUID.randomUUID().toString().replaceAll("-",""));
        location.setSerialNumber("0000");
        location.setSendToProDateTime("20201228174425");
        location.setLocationType(0);
        Response response = new JTTUtils().uploadLocation(location, null);
        System.out.println("============");
    }

    //车辆
    public static void main(String[] args) throws IOException {
//        UploadCarBaseInfoBean car = new UploadCarBaseInfoBean();
//        car.setGrossMass(new BigDecimal("7.91"));
//        car.setIssueDate("20181019");
//        car.setIssuingOrganizations("河北省石家庄市公安交通管理局");
//        car.setOwner("石家庄市鸿宇汽车运输有限公司");
//        car.setRegisterDate("20181019");
//        car.setRoadTransportCertificateNumber("130101015175");//道路运输证号
//        car.setUseCharacter("货运");
//        car.setVehicleEnergyType("B");
//        car.setVehicleType("H19");
//        car.setVehicleNumber("冀A196A0");
//        car.setVehicleTonnage(new BigDecimal("9.90"));
//        car.setVin("LGAX3A135J1011492");
//        car.setVehiclePlateColorCode("2");
//        Response response = new JTTUtils().uploadCar(car, null);
//        System.out.println("============");

        Workbook wb =null;
        Sheet sheet = null;
        Row row = null;
        List<UploadCarBaseInfoBean> list = null;
        String cellData = null;
        String filePath = "E:\\八秒车辆信息记录2.xlsx";
        String columns[] = {"vehicleNumber","vehiclePlateColorCode","vehicleType","owner","useCharacter","vin","issuingOrganizations","registerDate","issueDate","vehicleEnergyType","vehicleTonnage","grossMass","roadTransportCertificateNumber"};
        wb = readExcel(filePath);
        if(wb != null){
            //用来存放表中数据
            list = new ArrayList<UploadCarBaseInfoBean>();
            //获取第一个sheet
            sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            //获取第一行
            row = sheet.getRow(0);
            //获取最大列数
            int colnum = row.getPhysicalNumberOfCells();
            for (int i = 1; i<rownum; i++) {
//                Map<String,String> map = new LinkedHashMap<String,String>();
                UploadCarBaseInfoBean uploadCarBaseInfoBean=new UploadCarBaseInfoBean();
                row = sheet.getRow(i);
                if(row !=null){
                    for (int j=0;j<colnum;j++){
                        row.getCell(j).setCellType(Cell.CELL_TYPE_STRING);
                        cellData = (String) getCellFormatValue(row.getCell(j));
//                        cellData= row.getCell(j).getRichStringCellValue().getString();
                        if(columns[j].equals("vehicleNumber")){
                            uploadCarBaseInfoBean.setVehicleNumber(cellData);
                        }else  if(columns[j].equals("vehiclePlateColorCode")){
                            uploadCarBaseInfoBean.setVehiclePlateColorCode(cellData);
                        }else  if(columns[j].equals("vehicleType")){
                            uploadCarBaseInfoBean.setVehicleType(cellData);
                        }else  if(columns[j].equals("owner")){
                            uploadCarBaseInfoBean.setOwner(cellData);
                        }else  if(columns[j].equals("vin")){
                            uploadCarBaseInfoBean.setVin(cellData);
                        }else  if(columns[j].equals("useCharacter")){
                            uploadCarBaseInfoBean.setUseCharacter(cellData);
                        }else  if(columns[j].equals("issuingOrganizations")){
                            uploadCarBaseInfoBean.setIssuingOrganizations(cellData);
                        }else  if(columns[j].equals("registerDate")){
                            uploadCarBaseInfoBean.setRegisterDate(cellData);
                        }else  if(columns[j].equals("issueDate")){
                            uploadCarBaseInfoBean.setIssueDate(cellData);
                        }else  if(columns[j].equals("vehicleEnergyType")){
                            uploadCarBaseInfoBean.setVehicleEnergyType(cellData);
                        }else  if(columns[j].equals("vehicleTonnage")){
                            uploadCarBaseInfoBean.setVehicleTonnage(new BigDecimal(cellData));
                        }else  if(columns[j].equals("grossMass")){
                            uploadCarBaseInfoBean.setGrossMass(new BigDecimal(cellData));
                        }else  if(columns[j].equals("roadTransportCertificateNumber")){
                            uploadCarBaseInfoBean.setRoadTransportCertificateNumber(cellData);
                        }

                    }
                }else{
                    break;
                }
                list.add(uploadCarBaseInfoBean);
            }
        }
        if(list.size()>0){
            for(UploadCarBaseInfoBean uploadCarBaseInfoBean:list){
                Response response = new JTTUtils().uploadCar(uploadCarBaseInfoBean, null);
                System.out.println(JSONObject.toJSON(response));
                System.out.println("============");
            }
        }
//        //遍历解析出来的list
//        for (Map<String,String> map : list) {
//            for (Map.Entry<String,String> entry : map.entrySet()) {
//                System.out.print(entry.getKey()+":"+entry.getValue()+",");
//            }
//            System.out.println();
//        }
    }

    public static Workbook readExcel(String filePath){
        Workbook wb = null;
        if(filePath==null){
            return null;
        }
        String extString = filePath.substring(filePath.lastIndexOf("."));
        InputStream is = null;
        try {
            is = new FileInputStream(filePath);
            if(".xls".equals(extString)){
                return wb = new HSSFWorkbook(is);
            }else if(".xlsx".equals(extString)){
                return wb = new XSSFWorkbook(is);
            }else{
                return wb = null;
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return wb;
    }
    public static Object getCellFormatValue(Cell cell){
        Object cellValue = null;
        if(cell!=null){
            //判断cell类型
            switch(cell.getCellType()){
                case Cell.CELL_TYPE_NUMERIC:{
                    cellValue = String.valueOf(cell.getNumericCellValue());
//                    cellValue = cell.getRichStringCellValue().getString();
                    break;
                }
                case Cell.CELL_TYPE_FORMULA:{
                    //判断cell是否为日期格式
//                    if(DateUtil.isCellDateFormatted(cell)){
//                        //转换为日期格式YYYY-mm-dd
//                        cellValue = cell.getDateCellValue();
//                    }else{
//                        //数字
//                        cellValue = String.valueOf(cell.getNumericCellValue());
//                    }
                    cellValue = cell.getRichStringCellValue().getString();
                    break;
                }
                case Cell.CELL_TYPE_STRING:{
                    cellValue = cell.getRichStringCellValue().getString();
                    break;
                }
                default:
                    cellValue = "";
            }
        }else{
            cellValue = "";
        }
        return cellValue;
    }
    //司机
    public static void main1(String[] args) throws IOException {
        UploadDriverBaseInfoBean driver = new UploadDriverBaseInfoBean();
        driver.setDriverName("张建路");
        driver.setDrivingLicense("13292419711011811");
        driver.setIssuingOrganizations("河北省沧州市公安交通警察大队");
        driver.setQualificationCertificate("13292419711011811");
        driver.setTelephone("15075854430");
        driver.setValidPeriodFrom("20140319");
        driver.setValidPeriodTo("20240319");
        driver.setVehicleClass("A2");
        Response response = new JTTUtils().uploadDriver(driver, null);
        System.out.println("============");
    }

}
*/
